﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StatisticsApplication.WindowsForm
{
    public partial class RestrictControl : UserControl
    {
        private bool myStatus = false;

        /// <summary>
        /// 标示当前输入数据是否合法 true为合法。false是非法
        /// </summary>
        public bool MyStatus
        {

            get
            {
                return myStatus;
            }
            set 
            { 
                myStatus = value;
            }

        }
        public RestrictControl()
        {

            InitializeComponent();
            Disableall();
            EnableOne();



        }

        private void textBox1_Validated(object sender, EventArgs e)
        {

        }

        private void SetControl(int count)
        {
            Enableall();
            switch (count)
            {
                case 2:
                    textBox4.Enabled = false;
                    label4.Enabled = false;
                    goto case 3;
                case 3:
                    textBox5.Enabled = false;
                    label5.Enabled = false;
                    goto case 4;
                case 4:
                    textBox6.Enabled = false;
                    label6.Enabled = false;
                    goto case 5;
                case 5:
                    break;
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int num;
            try
            {
                num = Convert.ToInt16(textBox1.Text.ToString());
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(null, "输入组数不合法！必须输入大于1小于5的数字！", "温馨提示：", MessageBoxButtons.OK);
                return;
            }
            if (num > 5 || num < 2)
            {
                MessageBox.Show(null, "输入组数不合法！必须输入大于1小于5！", "温馨提示：", MessageBoxButtons.OK);
                return;
            }
            else
            {
                SetControl(num);
            }
        }


        public void GetGroupcount()
        {
            //int num;
            // try
            //{
            //    num = Convert.ToInt16(textBox1.Text.ToString());
            //}
            //catch(System.Exception ex)
            // {  
            //    return  
            //}
            //int [] groupcount=new int []

        }

        private void btEnsure_Click(object sender, EventArgs e)
        {
            myStatus = false;
            Disableall();
        }

        private void btCancle_Click(object sender, EventArgs e)
        {
            Disableall();
            EnableOne();

        }
        private void Disableall()
        {
            textBox1.Enabled = false;
            textBox2.Enabled = false;
            textBox3.Enabled = false;
            textBox4.Enabled = false;
            textBox5.Enabled = false;
            textBox6.Enabled = false;

            textBox2.Text = string.Empty;
            textBox3.Text = string.Empty;
            textBox4.Text = string.Empty;
            textBox5.Text = string.Empty;
            textBox6.Text = string.Empty;

            label1.Enabled = false;
            label2.Enabled = false;
            label3.Enabled = false;
            label4.Enabled = false;
            label5.Enabled = false;
            label6.Enabled = false;
        }
        private void Enableall()
        {
            textBox1.Enabled = true;
            textBox2.Enabled = true;
            textBox3.Enabled = true;
            textBox4.Enabled = true;
            textBox5.Enabled = true;
            textBox6.Enabled = true;

            label1.Enabled = true;
            label2.Enabled = true;
            label3.Enabled = true;
            label4.Enabled = true;
            label5.Enabled = true;
            label6.Enabled = true;
        }
        public void EnableOne()
        {
            textBox1.Enabled = true;
            label1.Enabled = true;
        }
    }
}
